home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / comm / nt16310.zip / NETEDIT.C_ / NETEDIT.C
C/C++ Source or Header  |  1996-04-10  |  3KB  |  103 lines

  1.  /**********************************************************************
  2.  *                   InterSoft International, Inc                      *
  3.  *                        Copyright (C) 1995                           *
  4.  ***********************************************************************
  5.  * System:   IBM PC                                                    *
  6.  * Program:  NETEDIT.C                                                 *
  7.  * Author:   K.R. Robinette                                            *
  8.  * Date:     August, 1995                                              *
  9.  * Function: Remote Editing Support                                    *
  10.  **********************************************************************/
  11. #include "stdio.h"
  12. #include "string.h"
  13. #include "sys/types.h"
  14. #include "sys/stat.h"
  15.  
  16.  char on[5]  = {"\033[5i"};
  17.  char off[5] = {"\033[3i"};
  18.  
  19.  main(argc,argv)
  20.  int argc;
  21.  char **argv;
  22.  {
  23.  int  len,flag,mode;
  24.  FILE *fd;
  25.  char line[1024],out[1024];
  26.  struct stat buf;
  27.  if(argc == 2)
  28.       {
  29.       if((stat(argv[1],&buf)) != 0)
  30.            {
  31.            printf("Error, could not open %s\n",argv[1]);
  32.            exit(-1);
  33.            }
  34.       mode = buf.st_mode;
  35.       if((fd = fopen(argv[1],"r")) == NULL)
  36.            {
  37.            printf("Error, could not open %s\n",argv[1]);
  38.            exit(-1);
  39.            }
  40.       if((fwrite(on,1,4,stdout)) != 4)
  41.            {
  42.            printf("Error, writing to network\n");
  43.            exit(-1);
  44.            }
  45.       while(1)
  46.            {
  47.            if(fgets(line,1023,fd) == NULL)
  48.                 break;
  49.            len = strlen(line);
  50.            fwrite(line,1,len,stdout);
  51.            }
  52.       fwrite(off,1,4,stdout);
  53.       }
  54.       else
  55.            {
  56.            printf("Input filename required\n");
  57.            exit(-2);
  58.            }
  59.  fclose(fd);
  60.  
  61.  system("stty -echo");
  62.  strcpy(out,argv[1]);
  63.  strcat(out,".new");
  64.  if((fd = fopen(out,"w")) == NULL)
  65.       {
  66.       system("stty echo");
  67.       printf("Error, could not open output file %s\n",out);
  68.       exit(-3);
  69.       }
  70.  line[0] = 0;
  71.  while(1)
  72.       {
  73.       if(fgets(line,sizeof(line)-1,stdin) == NULL)
  74.            break;
  75.       if(line[0] == 0x02)
  76.            break;
  77.       if(line[0] == 0x01)
  78.            break;
  79.       len = strlen(line);
  80.       fwrite(line,1,len,fd);
  81.       }
  82.  fclose(fd);
  83.  flag = line[0];
  84.  if(flag == 2)
  85.       remove(out);
  86.       else if(flag == 1)
  87.            {
  88.            remove(argv[1]);
  89.            strcpy(line,"mv ");
  90.            strcat(line,out);
  91.            strcat(line," ");
  92.            strcat(line,argv[1]);
  93.            system(line);
  94.            chmod(argv[1],mode);
  95.            }
  96.            else flag = 2;
  97.  system("stty echo");
  98.  if(flag == 2)
  99.       printf("File was not modified\n");
  100.       else
  101.       printf("File was modified\n");
  102.  }
  103.